package com.JFapp.controller;

import com.JFapp.domain.entity.Repair;
import com.JFapp.domain.entity.ResponseResult;
import com.JFapp.domain.vo.RepairVo;
import com.JFapp.eumns.AppHttpCodeEnum;
import com.JFapp.exception.SystemException;
import com.JFapp.service.RepairService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.parameters.P;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/repair")
@Api(tags = "前台维修单管理")
public class RepairController {

    @Autowired
    private RepairService repairService;

    @ApiOperation("新增订单")
    @PostMapping("/add")
    public ResponseResult addRepair(@RequestBody Repair repair){
        return repairService.addRepair(repair);
    }

    @ApiOperation("普通用户查询订单")
    @GetMapping("/selectByCreatId")
    public ResponseResult selectRepairByCreatId( Integer pageNum, Integer pageSize){
        return repairService.selectRepairByCreatId(pageNum, pageSize);
    }


    @ApiOperation("根据订单id修改订单内容")
    @PostMapping("/updateRepairById")
    public ResponseResult updateRepairById (@RequestBody Repair repair){
        return  repairService.updateRepairById(repair);
    }
    @ApiOperation("查询详细订单")
    @GetMapping("/{repairId}")
    public ResponseResult getRepairDetail(@PathVariable Long repairId){
        return repairService.getDetailById(repairId);
    }

    @ApiOperation("取消订单")
    @DeleteMapping("/cancel")
    public  ResponseResult cancelRepair(@RequestBody Repair repair){
        return repairService.cancelRepair(repair);
    }


    @ApiOperation("完成订单")
    @PostMapping("/complete")
    public ResponseResult complete(@RequestBody Repair repair){
        if(repair.getRepairId()!=null&&repair.getStatus()!=1){
            throw new SystemException(AppHttpCodeEnum.NOT_COMPLETE);
        }
        return repairService.complete(repair);
    }

}
